<template>
  <div class="search">
    <div class="content-page">
      <header>
        <h3>全文检索</h3>
        <div class="input-box">
          <el-input v-model="form.key" placeholder="关键字" class="input-with-select">
          </el-input>
        </div>
        <el-button type="primary" class="search-btn" @click="getList('all', form.key)">搜索</el-button>
      </header>
      <div class="m-t p-t">
        <el-radio-group v-model="form.type" size="large" @input="getRadioData">
          <el-radio-button :label="`全部（${allCount}）`" />
          <el-radio-button :label="`科研设施（${facilitiesCount}）`" />
          <el-radio-button :label="`仪器设备（${instrumentCount}）`" />
          <el-radio-button :label="`软件系统（${softwareCount}）`" />
          <!-- <el-radio-button label="地方资源（50）" />
        <el-radio-button label="政策法规（50）" />
        <el-radio-button label="工作动态（50）" /> -->
          <el-radio-button label="其他（0）" />
        </el-radio-group>
      </div>
      <main>
        <div class="top-search">
          排序：
          <el-radio-group v-model="form.sort" size="small" class="m-r" @input="getRadioData2">
            <el-radio-button label="按相似度" />
            <el-radio-button label="按发布时间" />
          </el-radio-group>
          搜索范围：
          <el-radio-group v-model="form.range" size="small" class="m-r">
            <el-radio-button label="全文搜索" />
            <el-radio-button label="只搜标题" />
          </el-radio-group>
          搜索日期：
          <el-date-picker v-model="form.date" type="date" placeholder="选择日期" size="small" />
          <span class="text-end"> 找到 {{allCount}} 条结果，查询耗时：0.069 </span>
        </div>
        <div class="content">
          <div class="left">
            <ul>
              <li v-for="(item, index) in contentList" :key="index">
                <p>
                  <span class="tag">{{ item.tag }}</span>
                  <span class="title" v-html="item.name" @click="goDetail(item.tag, item.rawData)"></span>
                </p>
                <p class="memo" v-html="item.memo"></p>
                <p class="company">
                  <span>{{ item.company }}</span>
                  <span>{{ item.date }}</span>
                </p>
              </li>
            </ul>
          </div>
          <div class="right">
            <div class="top-right">
              <el-tabs v-model="activeName" class="demo-tabs">
                <el-tab-pane label="热门搜索" name="first">
                  <ul class="hot">
                    <li v-for="(item, index) in listArr2" :key="item.key" :class="{ active: index == 0 }">
                      <span class="num">
                        <span>0{{ index + 1 }}</span>
                      </span>
                      <span class="title">
                        <span>{{ item.name }}</span>
                      </span>
                    </li>
                  </ul>
                </el-tab-pane>
              </el-tabs>
              <span class="more1">更多 ></span>
            </div>
            <div class="bottom-right">
              <el-tabs v-model="activeName" class="demo-tabs">
                <el-tab-pane label="关联搜索" name="first"> </el-tab-pane>
              </el-tabs>
              <span style="color: #888">暂无搜索的关键词</span>
            </div>
          </div>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
import {
  getSearchDataList
} from '@/api/yqgx/search'
export default {
  computed: {
    isSelect() {
      return this.$route.params.select
    },
    isKeyword() {
      return this.$route.params.keyword
    }
  },
  data() {
    return {
      form: {
        key: "",
        type: "",
        sort: "按相似度",
        range: "全文搜索",
        date: "",
      },
      activeName: "first",
      contentList: [{
        tag: "政策法规",
        name: "中华人民共和国科学技术进步法（2021修订）",
        company: "全国人民代表大会常务委员会",
        memo: "《中华人民共和国科学技术进步法》已由中华人民共和国第十三届全国人民代表大会常务委员会第三十二次会议于2021年12月24日修订通过，现予公布，自2022年1月1日起施行",
        date: "2023-01-01",
      },
      {
        tag: "政策法规",
        name: "中国人民解放军现役军官服役条例",
        company: "全国人民代表大会常务委员会",
        memo: "1988年9月5日第七届全国人民代表大会常务委员会第三次会议通过1988年9月5日中华人民共和国主席令第八号公布自1989年1月1日起施行。为了建设一支革命化、年轻化、知识化、专业化的军官队伍，以利于人民解放军完成国家赋予的任务、定制本条例",
        date: "2023-01-01",
      },
      {
        tag: "项目公告",
        name: "关于某集团2023年度某某平台运营服务质量的评价结果公式",
        company: "某某某单位",
        memo: "根据《某某集团单位运营服务质量评价办法》（某某某[2021]12号），我单位对某集团有限责任公司2023年度某系统运营服务质量分别进行了日常评价、年度评价和第三方服务满意度评价、并计算综合成绩。现将评价结果予以公示",
        date: "2023-01-01",
      },
      {
        tag: "政策法规",
        name: "武器装备研制设计师系统和行政指挥系统工作条例",
        company: "国务院、中央军委",
        memo: "第一条 为加强武器装备（含卫星系统，下同）研制工作中的责任制，以缩短研制周期，节约经费，保证质量，加速我军武器装备现代化建设，特制定本条例。第二条 武器装备研制设计师系统（以下简称设计师系统）是由各级设计师组成的跨建制、跨部门的技术指挥系统，负责武器装备研制中的...",
        date: "2023-01-01",
      },
      {
        tag: "项目公告",
        name: "关于某集团2023年第一季度某某平台运行服务质量的评价结果公示",
        company: "某某某单位",
        memo: "根据《某某集团单位运营服务质量评价办法》（某某某[2021]12号），我单位对某集团有限责任公司2023年度某系统运营服务质量分别进行了日常评价、年度评价和第三方服务满意度评价、并计算综合成绩。现将评价结果予以公示",
        date: "2023-01-01",
      },],
      listArr2: [
        {
          name: "病原微生物生物安全国家重点实验室",
          content: "",
          time: "2024.04",
          key: "15",
        },
        {
          name: "病原微生物生物安全国家重点实验室",
          content: "",
          time: "2023.07",
          key: "10",
        },
        {
          name: "蛋白质组学国家重点实验室",
          content: "",
          time: "2023.06",
          key: "08",
        },
        {
          name: "国家生物医学分析中心免疫学研究室",
          content: "",
          time: "2023.05",
          key: "06",
        },
        {
          name: "空气动力学国家重点实验室",
          content: "",
          time: "2023.04",
          key: "01",
        },
        {
          name: "磁刺激定位导航系统",
          content: "",
          time: "2023.06",
          key: "08",
        },
        {
          name: "多模式活体成像系统（光子频谱扫描成像仪）",
          content: "",
          time: "2023.05",
          key: "06",
        },
        {
          name: "BD FACSCalibur流式细胞仪",
          content: "",
          time: "2023.04",
          key: "01",
        },
      ],
      allCount: 0,
      facilitiesCount: 0,
      instrumentCount: 0,
      softwareCount: 0,
      allList: []
    }
  },
  mounted() {
    this.getList(this.isSelect, this.isKeyword)
    // console.log(this.isSelect);
    // console.log(this.isKeyword);
    this.form.key = this.isKeyword
  },
  methods: {
    getRadioData() {
      if (this.form.type.includes('科研设施')) {
        this.contentList = this.allList.filter((item) => item.tag == '科研设施')
      } else if (this.form.type.includes('仪器设备')) {
        this.contentList = this.allList.filter((item) => item.tag == '仪器设备')
      } else if (this.form.type.includes('软件系统')) {
        this.contentList = this.allList.filter((item) => item.tag == '软件系统')
      } else if (this.form.type.includes('其他')) {
        this.contentList = []
      } else {
        this.contentList = this.allList
        this.form.type = `全部（${this.allCount}）`
      }
    },
    getRadioData2() {
      if (this.form.sort == '按发布时间') {
        this.sortByDate()
      } else {
        this.getList('all', this.isKeyword)
      }
    },
    sortByDate() {
      this.contentList = this.contentList.sort(function (a, b) {
        var dateA = new Date(a.date);
        var dateB = new Date(b.date);
        return dateB - dateA;
      });
      // console.log(midList,'midList');
      // 
    },
    getList(select, keyword) {
      let that = this
      this.allCount = 0
      this.facilitiesCount = 0
      this.instrumentCount = 0
      this.softwareCount = 0
      getSearchDataList(select, keyword).then((res) => {
        this.allList = res.data.map((item) => {
          this.allCount = this.allCount + 1
          if (item.tag == '科研设施')
            this.facilitiesCount = this.facilitiesCount + 1
          if (item.tag == '仪器设备')
            this.instrumentCount = this.instrumentCount + 1
          if (item.tag == '软件系统')
            this.softwareCount = this.softwareCount + 1
          let midItem = item
          midItem.name = that.highlightText(item.name, keyword)
          midItem.memo = that.highlightText(item.memo, keyword)
          return midItem
        })
        this.getRadioData()
      })
    },
    highlightText(inputText, searchText) {
      // 使用 searchText 变量替换文本中的字符串
      const regex = new RegExp(searchText, 'g');
      let highlightedText = inputText.replace(regex, `<span style="color: red">${searchText}</span>`);
      return highlightedText
    },
    goDetail(tag, item) {
      console.log('%c [ item ]-219', 'font-size:13px; background:pink; color:#bf2c9f;', item)
      if (item) {
        if (!item.Favorite)
          item.Favorite = '0'
        if (tag == '科研设施')
          this.$router.push({
            name: 'detailPage',
            params: { item: item }
          })
        if (tag == '仪器设备')
          this.$router.push({
            name: 'yiqiDetailPage',
            params: { item: item }
          })
        if (tag == '软件系统')
          this.$router.push({
            name: 'softDetailPage',
            params: { item: item }
          })

      }
    },
  }
}

</script>

<style lang="less" scoped>
  :deep(.input-box) {
    font-size: 16px !important;
    border: 1px solid #f2f2f2;
    width: 70%;
    box-shadow: 5px 5px 10px rgb(172, 172, 172);

    .el-input {
      width: 100% !important;
    }

    border-radius: 4px;

    .el-input__wrapper,
    .el-input__inner {
      border: none !important;
      box-shadow: none !important;
      color: #999 !important;
    }

    .el-input-group__prepend,
    .el-input__wrapper,
    .el-input-group__append {
      background: transparent;
      border: none !important;
      box-shadow: none !important;
      color: #999 !important;
    }

    .search-btn {
      background-color: #007be2;
      padding: 5px 30px;
      margin-right: 0px;
      color: #fff;
    }
  }

  .search {
    padding: 30px 0;
  }

  .content-page {
    width: 70%;
    margin: 0 auto;
    padding: 20px;
    background: #fff;
    border-radius: 4px;
  }

  header {
    width: 60%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;

    h3 {
      font-size: 25px;
      color: #007be2;
      font-weight: 600;
    }
  }

  main {
    .top-search {
      margin-top: 20px;
      background: rgb(235, 238, 245);
      display: flex;
      align-items: center;
      padding: 15px 20px;
      position: relative;

      .text-end {
        position: absolute;
        right: 20px;
      }
    }

    .content {
      display: flex;

      .left {
        width: 70%;
        padding: 20px;

        li {
          margin-bottom: 40px;

          p {
            margin-bottom: 10px;
          }

          .tag {
            padding: 5px 8px;
            background-color: #eae8e8;
            margin-right: 20px;
          }

          .title {
            font-weight: 600;
          }

          .memo {
            color: #888888;
            line-height: 30px;
          }

          .company {
            display: flex;
            justify-content: space-between;
            color: #c5c2c2;
          }
        }
      }

      .right {
        width: 30%;
        margin-top: 20px;

        .top-right {
          background: #fff;
          padding: 16px 20px;
          position: relative;
          border: 1px solid #d4d5d6;

          .more1 {
            position: absolute;
            right: 20px;
            top: 20px;
          }
        }

        .bottom-right {
          margin-top: 10px;
          border: 1px solid #d4d5d6;
          padding: 16px 20px;
        }

        :deep(.demo-tabs) {
          .el-tabs__item {
            font-size: 18px;
            color: #333;
            font-weight: 600;
          }
        }

        .first {
          li {
            display: flex;
            align-items: center;
            margin-bottom: 30px;

            &:last-child {
              margin-bottom: 0;
            }

            .num {
              display: inline-block;
              width: 56px;
              height: 56px;
              padding: 5px;
              background: #b9c1c8;
              display: flex;
              flex-direction: column;
              align-items: center;
              font-size: 20px;
              color: #fff;
              margin-right: 16px;

              .time {
                font-size: 12px;
              }
            }

            .des {
              width: 90%;
              display: flex;
              flex-direction: column;
              font-size: 16px;
              color: #333;

              .content {
                font-size: 14px;
                color: #999;
                padding-top: 6px;
              }

              .title,
              .content {
                display: inline-block;
                width: 100%;
                white-space: nowrap;
                position: relative;
                text-overflow: ellipsis;
                overflow: hidden;
              }

              .title {
                width: 63%;
              }
            }

            &.active {
              .num {
                background: #007be2;
              }

              .des {
                .title {
                  color: #007be2;
                }
              }
            }
          }
        }

        .hot {
          li {
            display: flex;
            align-items: center;
            margin-bottom: 27.8px;

            &:last-child {
              margin-bottom: 0;
            }

            .num {
              display: inline-block;
              margin-top: 2px;
              margin-right: 8px;
              font-weight: 16px;
              color: #a4aaae;
            }

            .title {
              display: inline-block;
              width: 100%;
              white-space: nowrap;
              position: relative;
              text-overflow: ellipsis;
              overflow: hidden;
            }

            &:nth-child(1) {
              .num {
                background: #fb5858;
                border-radius: 4px;
                color: #fff;
                padding: 3px;
              }
            }

            &:nth-child(2) {
              .num {
                background: #ff7151;
                border-radius: 4px;
                color: #fff;
                padding: 3px;
              }
            }

            &:nth-child(3) {
              .num {
                background: #ff974f;
                border-radius: 4px;
                color: #fff;
                padding: 3px;
              }
            }
          }
        }
      }
    }
  }
</style>
